const dynamicService = require('@/services/dynsmic.service')
const JsonResult = require('@/utils/httpResponse.util')

class DynamicController {
  async findPage (req, response) {
    const { pageNo, pageSize, searchKeywords, type } = req.query
    try {
      const data = await dynamicService.findPage(pageNo, pageSize, searchKeywords, type)
      JsonResult.success({
        req,
        response,
        data,
        message: '查询成功'
      })
    } catch (error) {
      JsonResult.fail({ req, response, error, message: '查询失败' })
    }
  }

  async batchDeleteByIds (req, response) {
    const ids = req.body.ids
    try {
      const data = await dynamicService.batchDelete(ids)
      if (data?.errorMessage) {
        return JsonResult.fail({ req, response, message: data.errorMessage })
      }
      JsonResult.success({
        req,
        response,
        data,
        message: '删除成功'
      })
    } catch (error) {
      JsonResult.fail({ req, response, error, message: '删除失败' })
    }
  }
}

module.exports = new DynamicController()
